extends Resource
class_name Model

var previous_number: float = 0
var current_number: float = 0
var current_operator: String = ""
var has_current_number: bool = false
var decimal_places: int = 0  # 添加此行以跟踪小数点后有多少数字

func clear() -> void:
	current_number = 0
	previous_number = 0
	current_operator = ""
	has_current_number = false
	decimal_places = 0  # 重置小数点位置

func evaluate_expression() -> void:
	var result: float = 0.0
	match current_operator:
		"+" : result = previous_number + current_number
		"-" : result = previous_number - current_number
		"*" : result = previous_number * current_number
		"/" : 
			if current_number != 0:
				result = previous_number / current_number
			else:
				print("Division by zero!")
		_:
			print("Unsupported operator: ", current_operator)
	previous_number = 0
	current_number = result
	current_operator = ""
	has_current_number = true
	_update_decimal_places(current_number)

func _update_decimal_places(value: float) -> void:
	var value_str = str(value)
	if "." in value_str:
		decimal_places = value_str.length() - value_str.find(".")
	else:
		decimal_places = 0
